{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "777.0092497628884\n"
     ]
    }
   ],
   "source": [
    "import akshare as ak\n",
    "\n",
    "\n",
    "# subscribe_list = ak.futures_foreign_commodity_subscribe_exchange_symbol()\n",
    "# print(subscribe_list)\n",
    "# COMEX白银    SI\n",
    "# COMEX黄金    GC\n",
    "# CME-瘦肉猪   LHC\n",
    "# 布伦特原油   OIL\n",
    "# 伦敦金   XAU\n",
    "# 伦敦银   XAG\n",
    "# 伦敦铂金   XPT\n",
    "# 伦敦钯金   XPD\n",
    "# 马棕油  FCPO\n",
    "futures_foreign_commodity_realtime_df = ak.futures_foreign_commodity_realtime(symbol=['XAU', 'GC'])\n",
    "# futures_foreign_commodity_realtime_df = futures_foreign_commodity_realtime_df.loc[futures_foreign_commodity_realtime_df['名称'] == 'COMEX黄金']\n",
    "# print(futures_foreign_commodity_realtime_df)\n",
    "\n",
    "\n",
    "def convert_gold_price_to_cny_per_gram(gold_price_usd_per_ounce, offshore_cny_rate):\n",
    "    \"\"\"\n",
    "    根据伦敦金价（美元/盎司）和离岸人民币汇率，计算伦敦金价的人民币价格（人民币/克）。\n",
    "\n",
    "    参数:\n",
    "        gold_price_usd_per_ounce (float): 伦敦金价（美元/盎司）\n",
    "        offshore_cny_rate (float): 离岸人民币汇率（美元兑人民币）\n",
    "\n",
    "    返回:\n",
    "        float: 伦敦金价的人民币价格（人民币/克）\n",
    "    \"\"\"\n",
    "    grams_per_ounce = 31.1035\n",
    "    return (gold_price_usd_per_ounce * offshore_cny_rate) / grams_per_ounce\n",
    "\n",
    "offshore_cny_rate = 7.19277\n",
    "\n",
    "\n",
    "\n",
    "# print('min:')\n",
    "# print(convert_gold_price_to_cny_per_gram(3222 , offshore_cny_rate))\n",
    "# print('mid:')\n",
    "# print(convert_gold_price_to_cny_per_gram(2912, offshore_cny_rate))\n",
    "# print('max:')\n",
    "# print(convert_gold_price_to_cny_per_gram(2943, offshore_cny_rate))\n",
    "print(convert_gold_price_to_cny_per_gram(3360, offshore_cny_rate))\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "伦敦金银比 89.75397072563065\n",
      "上海金银比 84.12145345943256\n",
      "金银比min 602.6999999999999\n",
      "金银比mid 642.88\n",
      "金银比max 683.06\n",
      "金银比max 723.24\n"
     ]
    }
   ],
   "source": [
    "# 上海白银\n",
    "silver_price = 8.036\n",
    "print('伦敦金银比', 2882 / 32.11)\n",
    "print('上海金银比', 676 / silver_price)\n",
    "print('金银比min', silver_price * 75)\n",
    "print('金银比mid', silver_price * 80)\n",
    "print('金银比max', silver_price * 85)\n",
    "print('金银比max', silver_price * 90)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "黄金逻辑\n",
    "\n",
    "- 长期，货币政策 + 美元 + 通胀（现在肯定放水，通胀，美元指数高位）\n",
    "- 中期，金银比预估止盈止损点\n",
    "- 短期，地缘政治，国家冲突（如加关税等），战争"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
